package com.sojson.util.security.springsecurity.service.impl;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import com.sojson.config.exception.TransErrorCode;
import com.sojson.result.Result;
import com.sojson.util.servlet.ServletUtil;

/**
 * 认证失败处理类,返回未授权(SpringSecurity设置的登录过滤)
 * 
 * @author liu
 * @date 2021-04-14
 */
@Component
public class AuthenticationErrService implements AuthenticationEntryPoint {

    /**
     * 认证失败
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
        throws IOException {
        ServletUtil.out(response, Result.fail(TransErrorCode.NOT_LOGIN));
    }

}